package com.example.jwtjava.config;

import com.example.jwtjava.common.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @Author 宋伟宁
 * @Date 2023/10/23
 * @Version 1.0
 **/
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Bean
    public TokenInterceptor tokenInterceptor(){
        return  new TokenInterceptor();
    }
    /**
     * 重写注册拦截器的方法
     * @param registry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor())
                //拦截所有请求
                .addPathPatterns("/**")
                .excludePathPatterns("/login");
        super.addInterceptors(registry);
    }

}
